/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2024.
 * Description: RTOS Process Context header
 * Create: 2021-08-15
 */
#ifndef __RTOS_RTPC_H_
#define __RTOS_RTPC_H_

#include <linux/sched.h>

#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
#define rtpc_set_task_state(tsk, state_value)		\
	do {											\
		(tsk)->task_state_change = _THIS_IP_;		\
		/* This memory barrier copy from set_current_state() */ \
		smp_store_mb((tsk)->state, (state_value));	\
	} while (0)
#else
#define rtpc_set_task_state(tsk, state_value)		\
	/* This memory barrier copy from set_current_state() */ \
	smp_store_mb((tsk)->state, (state_value))
#endif

#ifdef CONFIG_ARM64
void rtpc_correct_task_struct(struct task_struct *tsk);
void rtpc_recover_task_struct(struct task_struct *tsk);
void rtpc_recover_task_stack(void *start_sp, const void *save_kstack,
			     size_t kstack_size);
void rtpc_set_next_task(struct rq *rq, struct task_struct *next);

static inline void rtpc_switch_pt_regs(struct pt_regs *dest_regs, struct pt_regs *src_regs)
{
	memcpy(dest_regs, src_regs, sizeof(struct pt_regs));
}
#else
long rtpc_finish_task_switch(struct task_struct *const prev);
long rtpc_wake_handle(void);
#endif
void rtpc_sched_switch(struct task_struct *prev, struct task_struct *next);

void rtpc___schedule(bool preempt);

static inline void rtpc_schedule_preempt_disabled(void)
{
	rtpc___schedule(false);
}
#endif
